/****************************************************
          File Name:sem_trywait.c
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Sat 20 Sep 2014 07:22:01 PM CST
*****************************************************/

#include"posix_ipc.h"

int main(int argc, char *argv[])
{
    Usage(argc,"/sem",argv[0],argv[1]);

    sem_t *sem;
    int flag=0;

    sem=sem_open(argv[1],flag);
    if(sem==SEM_FAILED)
        err("sem_open");

    if(sem_trywait(sem)==-1)
    {
        if(errno==EAGAIN)
        {
            printf("trywait works\n");
            exit(EXIT_FAILURE);
        }
        else
            err("sem_trywait");
    }
    printf("semaphore -1\n");
    exit(EXIT_SUCCESS);
}
